﻿using System.Collections.Generic;
using System.Runtime.Serialization;
using UnityEngine.Scripting;

namespace GMME.Model.Rtm
{
    [DataContract]
    public class Property
    {
        public Property(string key, string value)
        {
            Key = key;
            Value = value;
        }

        [DataMember(Name = "key")] [Preserve] public string Key { get; set; }

        [DataMember(Name = "value")]
        [Preserve]
        public string Value { get; set; }
    }


    [DataContract]
    public class SetPropertiesReq
    {
        [DataMember(Name = "channelId")]
        [Preserve]
        public string ChannelId { get; set; }


        [DataMember(Name = "properties")]
        [Preserve]
        public List<Property> Properties { get; set; }

        /**
         * 将list的Properties转为dict
         */
        public void ConvertToPropertiesList(Dictionary<string, string> dictionary)
        {
            if (dictionary != null)
            {
                List<Property> mapList = new();
                foreach (var item in dictionary) mapList.Add(new Property(item.Key, item.Value));
                Properties = mapList;
            }
        }

        /**
         * 将list的Properties转为dict
         */
        public Dictionary<string, string> ConvertPropertiesToDict()
        {
            var dict = new Dictionary<string, string>();
            if (Properties != null)
                foreach (var property in Properties)
                    dict.Add(property.Key, property.Value);

            return dict;
        }
    }
}